package jvms.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

/**
 * Created by pc on 2015/5/4.
 */

public class ProxyFactory {
    //any class, object
    Class  cls;
    InvocationHandler h;

    public ProxyFactory(String className, InvocationHandler h) {
        try {
            cls = Class.forName(className);
            this.h = h;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }


    //get instance object
    public Object createProxyObject() {
        return Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), h);
    }
}
